<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActiveSupport::XmlMini_NokogiriSAX::HashBuilder</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/github.css" type="text/css" media="screen" />
<script src="../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Class</span> 
            ActiveSupport::XmlMini_NokogiriSAX::HashBuilder 
            
                <span class="parent">&lt; 
                    
                    Nokogiri::XML::SAX::Document
                    
                </span>
            
        </h1>
        <ul class="files">
            
            <li><a href="../../../files/activesupport/lib/active_support/xml_mini/nokogirisax_rb.html">activesupport/lib/active_support/xml_mini/nokogirisax.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  
    <div class="description">
      
<p><a href="../../Class.html">Class</a> that will build the hash while the XML
document is being parsed using SAX events.</p>

    </div>
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>C</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="HashBuilder.html#method-i-cdata_block">cdata_block</a>,
              </li>
            
              
              <li>
                <a href="HashBuilder.html#method-i-characters">characters</a>,
              </li>
            
              
              <li>
                <a href="HashBuilder.html#method-i-current_hash">current_hash</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>E</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="HashBuilder.html#method-i-end_document">end_document</a>,
              </li>
            
              
              <li>
                <a href="HashBuilder.html#method-i-end_element">end_element</a>,
              </li>
            
              
              <li>
                <a href="HashBuilder.html#method-i-error">error</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>S</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="HashBuilder.html#method-i-start_document">start_document</a>,
              </li>
            
              
              <li>
                <a href="HashBuilder.html#method-i-start_element">start_element</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    
      <!-- Section constants -->
      <div class="sectiontitle">Constants</div>
      <table border='0' cellpadding='5'>
        
          <tr valign='top'>
            <td class="attr-name">CONTENT_KEY</td>
            <td>=</td>
            <td class="attr-value">'__content__'.freeze</td>
          </tr>
          
            <tr valign='top'>
              <td>&nbsp;</td>
              <td colspan="2" class="attr-desc"></td>
            </tr>
          
        
          <tr valign='top'>
            <td class="attr-name">HASH_SIZE_KEY</td>
            <td>=</td>
            <td class="attr-value">'__hash_size__'.freeze</td>
          </tr>
          
            <tr valign='top'>
              <td>&nbsp;</td>
              <td colspan="2" class="attr-desc"></td>
            </tr>
          
        
      </table>
    


    
      <!-- Section attributes -->
      <div class="sectiontitle">Attributes</div>
      <table border='0' cellpadding='5'>
        
          <tr valign='top'>
            <td class='attr-rw'>
              [R]
            </td>
            <td class='attr-name'>hash</td>
            <td class='attr-desc'></td>
          </tr>
        
      </table>
    


    <!-- Methods -->
        
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-cdata_block">
            
              <b>cdata_block</b>(string)
            
            <a href="HashBuilder.html#method-i-cdata_block" name="method-i-cdata_block" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-characters">
            
              <b>characters</b>(string)
            
            <a href="HashBuilder.html#method-i-characters" name="method-i-characters" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
            <div class="aka">
              Also aliased as: <a href="HashBuilder.html#method-i-cdata_block">cdata_block</a>
            </div>
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-characters_source')" id="l_method-i-characters_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/187969069a1d76b93088ec8f574b8c80252dbb51/activesupport/lib/active_support/xml_mini/nokogirisax.rb#L60" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-characters_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/xml_mini/nokogirisax.rb, line 60</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">characters</span>(<span class="ruby-identifier">string</span>)
  <span class="ruby-identifier">current_hash</span>[<span class="ruby-constant">CONTENT_KEY</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">string</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-current_hash">
            
              <b>current_hash</b>()
            
            <a href="HashBuilder.html#method-i-current_hash" name="method-i-current_hash" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-current_hash_source')" id="l_method-i-current_hash_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/187969069a1d76b93088ec8f574b8c80252dbb51/activesupport/lib/active_support/xml_mini/nokogirisax.rb#L23" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-current_hash_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/xml_mini/nokogirisax.rb, line 23</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">current_hash</span>
  <span class="ruby-ivar">@hash_stack</span>.<span class="ruby-identifier">last</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-end_document">
            
              <b>end_document</b>()
            
            <a href="HashBuilder.html#method-i-end_document" name="method-i-end_document" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-end_document_source')" id="l_method-i-end_document_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/187969069a1d76b93088ec8f574b8c80252dbb51/activesupport/lib/active_support/xml_mini/nokogirisax.rb#L32" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-end_document_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/xml_mini/nokogirisax.rb, line 32</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">end_document</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-string">&quot;Parse stack not empty!&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@hash_stack</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&gt;</span> <span class="ruby-number">1</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-end_element">
            
              <b>end_element</b>(name)
            
            <a href="HashBuilder.html#method-i-end_element" name="method-i-end_element" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-end_element_source')" id="l_method-i-end_element_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/187969069a1d76b93088ec8f574b8c80252dbb51/activesupport/lib/active_support/xml_mini/nokogirisax.rb#L53" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-end_element_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/xml_mini/nokogirisax.rb, line 53</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">end_element</span>(<span class="ruby-identifier">name</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">current_hash</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">current_hash</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-constant">HASH_SIZE_KEY</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">current_hash</span>[<span class="ruby-constant">CONTENT_KEY</span>].<span class="ruby-identifier">blank?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">current_hash</span>[<span class="ruby-constant">CONTENT_KEY</span>] <span class="ruby-operator">==</span> <span class="ruby-string">''</span>
    <span class="ruby-identifier">current_hash</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-constant">CONTENT_KEY</span>)
  <span class="ruby-keyword">end</span>
  <span class="ruby-ivar">@hash_stack</span>.<span class="ruby-identifier">pop</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-error">
            
              <b>error</b>(error_message)
            
            <a href="HashBuilder.html#method-i-error" name="method-i-error" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-error_source')" id="l_method-i-error_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/187969069a1d76b93088ec8f574b8c80252dbb51/activesupport/lib/active_support/xml_mini/nokogirisax.rb#L36" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-error_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/xml_mini/nokogirisax.rb, line 36</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">error</span>(<span class="ruby-identifier">error_message</span>)
  <span class="ruby-identifier">raise</span> <span class="ruby-identifier">error_message</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-start_document">
            
              <b>start_document</b>()
            
            <a href="HashBuilder.html#method-i-start_document" name="method-i-start_document" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-start_document_source')" id="l_method-i-start_document_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/187969069a1d76b93088ec8f574b8c80252dbb51/activesupport/lib/active_support/xml_mini/nokogirisax.rb#L27" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-start_document_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/xml_mini/nokogirisax.rb, line 27</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">start_document</span>
  <span class="ruby-ivar">@hash</span> = {}
  <span class="ruby-ivar">@hash_stack</span> = [<span class="ruby-ivar">@hash</span>]
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-start_element">
            
              <b>start_element</b>(name, attrs = [])
            
            <a href="HashBuilder.html#method-i-start_element" name="method-i-start_element" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-start_element_source')" id="l_method-i-start_element_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/187969069a1d76b93088ec8f574b8c80252dbb51/activesupport/lib/active_support/xml_mini/nokogirisax.rb#L40" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-start_element_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/xml_mini/nokogirisax.rb, line 40</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">start_element</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">attrs</span> = [])
  <span class="ruby-identifier">new_hash</span> = { <span class="ruby-constant">CONTENT_KEY</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">''</span> }.<span class="ruby-identifier">merge!</span>(<span class="ruby-constant">Hash</span>[<span class="ruby-identifier">attrs</span>])
  <span class="ruby-identifier">new_hash</span>[<span class="ruby-constant">HASH_SIZE_KEY</span>] = <span class="ruby-identifier">new_hash</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">+</span> <span class="ruby-number">1</span>

  <span class="ruby-keyword">case</span> <span class="ruby-identifier">current_hash</span>[<span class="ruby-identifier">name</span>]
    <span class="ruby-keyword">when</span> <span class="ruby-constant">Array</span> <span class="ruby-keyword">then</span> <span class="ruby-identifier">current_hash</span>[<span class="ruby-identifier">name</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">new_hash</span>
    <span class="ruby-keyword">when</span> <span class="ruby-constant">Hash</span>  <span class="ruby-keyword">then</span> <span class="ruby-identifier">current_hash</span>[<span class="ruby-identifier">name</span>] = [<span class="ruby-identifier">current_hash</span>[<span class="ruby-identifier">name</span>], <span class="ruby-identifier">new_hash</span>]
    <span class="ruby-keyword">when</span> <span class="ruby-keyword">nil</span>   <span class="ruby-keyword">then</span> <span class="ruby-identifier">current_hash</span>[<span class="ruby-identifier">name</span>] = <span class="ruby-identifier">new_hash</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-ivar">@hash_stack</span>.<span class="ruby-identifier">push</span>(<span class="ruby-identifier">new_hash</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    